package cn.wolfcode.rbac.web.controller;

import cn.wolfcode.rbac.domain.Department;
import cn.wolfcode.rbac.service.IDepartmentService;
import cn.wolfcode.rbac.util.QueryObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * Created by Blank9 on 2020/7/12.
 */
@Controller
public class DepartmentController {
    @Autowired
    private IDepartmentService departmentService;

    @RequestMapping("/department/list")                       //接收前台浏览器发送的请求，若匹配则执行
    public String list(Model model, QueryObject queryObject){
        model.addAttribute("list",departmentService.query(queryObject));
        return "department/list";
    }

    @RequestMapping("/department/delete")
    public String delete(Long id){
        departmentService.delete(id);
        return "redirect:/department/list.do";
    }

    @RequestMapping("/department/input")
    public String input(Model model,Long id){
        if (id != null) {
            Department department = departmentService.get(id);
            model.addAttribute("entity",department);
        }
        return "department/input";
    }

    @RequestMapping("/department/saveOrUpdate")
    public String saveOrUpdate(Department department){
        departmentService.saveOrUpdate(department);
        return "redirect:/department/list.do";
    }


}
